//
// Created by youle on 20-1-14.
//

#ifndef PROJECT_UTILS_H
#define PROJECT_UTILS_H

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <string>
#include <chrono>
#include <cstdint>
#include <time.h>
#include <vector>

typedef struct _VertPoint {
    _VertPoint() = default;
    _VertPoint(float _x, float _y) :
            x(_x), y(_y) {}
    _VertPoint(int & _x, int & _y) :
            x(_x), y(_y) {}
    float x = 0.0;
    float y = 0.0;
}VertPoint;


inline uint64_t nanos_since_boot() {
    struct timespec t;
    clock_gettime(CLOCK_BOOTTIME, &t);
    return t.tv_sec * 1000000000ULL + t.tv_nsec;
}

inline uint64_t mills_since_boot() {
    struct timespec t;
    clock_gettime(CLOCK_BOOTTIME, &t);
    return t.tv_sec * 1000ULL + t.tv_nsec/1000000ULL;
}

inline uint64_t mills_UTC() {
    struct timespec t;
    clock_gettime(CLOCK_REALTIME, &t);
    return t.tv_sec * 1000ULL + t.tv_nsec/1000000ULL;
}

const std::string GetStrCurrentSystemTime();

constexpr inline int U(const char* str)
{
    return str[0] + (str[1] ? U(str + 1) : 0);
}

int IsFileExist(const char* file_path);

int IsDirExist(const char* dir_path);

int CreateDir(const char *sPathName);

//如果是小端则返回1，如果是大端则返回0
int JudgeSystem();

// 小端 转 大端（网络字节序）
uint64_t Host2Net(const uint64_t & i64_host);

//P为线外一点，AB为线段两个端点
float GetDist_P2L(const VertPoint& pointP, const VertPoint& pointA, const VertPoint& pointB);

//P为线外一点，AB为线段两个端点, 获得点x轴 跟线焦点的x坐标
int GetX_P2L(const VertPoint& pointP, const VertPoint& pointA, const VertPoint& pointB);

bool PointInPnpoly(const std::vector<VertPoint>& verts, const VertPoint & point);

const std::string & GetRootDir();

#endif //PROJECT_UTILS_H
